package com.landleaf.smarthome.db.converter;

import com.google.gson.reflect.TypeToken;
import com.landleaf.smarthome.model.DeviceModel;
import com.landleaf.smarthome.util.JsonUtils;

import org.greenrobot.greendao.converter.PropertyConverter;

import java.lang.reflect.Type;
import java.util.List;

/**
 * When I wrote this, only God and I understood what I was doing
 * Now, God only knows
 * Created by 海航
 * 2019/9/29
 * 功能描述:
 */
public class DeviceConverter implements PropertyConverter<List<DeviceModel>, String> {
    @Override
    public List<DeviceModel> convertToEntityProperty(String databaseValue) {
        Type type = new TypeToken<List<DeviceModel>>() {}.getType();
        return JsonUtils.jsonToObj(databaseValue,type);
    }

    @Override
    public String convertToDatabaseValue(List<DeviceModel> entityProperty) {
        return JsonUtils.objToJson(entityProperty);
    }
}
